package cn.doitedu.datayi.data_service.controller;

import cn.doitedu.datayi.data_service.dao.PlatformMetaDao;
import cn.doitedu.datayi.data_service.po.FunnelStatistic;
import cn.doitedu.datayi.data_service.service.YieePlatFormPrestoService;
import cn.doitedu.datayi.data_service.vo.FunnelDefineVo;
import cn.doitedu.datayi.data_service.vo.FunnelStatisticVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author 涛哥
 * @nick_name "deep as the sea"
 * @contact qq:657270652 wx:doit_edu
 * @site www.doitedu.cn
 * @date 2021-02-02
 * @desc 为数易分析平台上的模板分析功能提供的controller
 */

@RestController
public class YieePlatFormPrestoController {

    @Autowired
    YieePlatFormPrestoService yieePlatFormPrestoService;

    @RequestMapping(method = RequestMethod.POST,value = "/api/v1/yiee/funnel/create")
    public FunnelStatisticVo funnelCreateQuery(@RequestBody FunnelDefineVo vo) throws Exception {

        if(vo == null){
            FunnelStatisticVo resVo = new FunnelStatisticVo();
            resVo.set(vo.getFunnelName(),500,"fail",null);

            return resVo;
        }

        // 查询presto，获取漏斗统计结果
        ArrayList<FunnelStatistic> lst = yieePlatFormPrestoService.funnelQuery(vo);

        // 保存漏斗定义信息
        yieePlatFormPrestoService.saveFunnelDefinition(vo);


        // 构造返回对象
        FunnelStatisticVo resVo = new FunnelStatisticVo();
        resVo.set(vo.getFunnelName(),200,"success",lst);

        return resVo;
    }



}
